<!DOCTYPE html>
<html lang="en">
<head>
    <include file="Common/top"/>
    <include file="Common/import_plugin"/>
</head>
<body>
<include file="Common/nav_menu"/>
<form action="__SELF__" method="post" class="layui-form">
    <table class="layui-table">
        <tr>
            <td>景区名称</td>
            <td><input type="text" name="name" class="layui-input" value="{$info.name}"></td>
        </tr>
        <tr>
            <td>缩略图</td>
            <td>
                <button type="button" class="layui-btn layui-btn-danger" id="test1">上传图片</button>
                <input type="hidden" name="thumb" value="{$info.thumb}">
                <div class="layui-upload-list">
                    <img class="layui-upload-img" src="{:thumb($info['thumb'])}" id="demo1">
                    <p id="demoText"></p>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" class="layui-btn layui-btn-normal layui-btn-block">
            </td>
        </tr>
    </table>
</form>
<script>
    layui.use(['form', 'laydate', 'upload'], function () {
        var $ = layui.jquery,
            form = layui.form,
            laydate = layui.laydate,
            upload = layui.upload;
        laydate.render({
            elem: 'input[name=starttime]'
        });
        laydate.render({
            elem: 'input[name=overtime]'
        });


        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: "{:U('update_pic')}"
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                console.log(res);
                if (!res.status) {
                    return layer.msg('上传失败');
                }
                else {
                    $('input[name=thumb]').val(res.info.file.savepath + res.info.file.savename);
                    return layer.msg('上传成功');
                }
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    })
</script>
</body>
</html>